﻿Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.String
Imports IDServer
Imports System.Text
Imports System.Collections
Imports CrystalDecisions.CrystalReports.Engine


Public Class Frm_SALPOSrecordFind

    Implements IDServer.IDServer.IDServer


    Private M_Ds As DataSet
    Private mDatasetA As DataSet
    Private mDatasetB As DataSet
    Private mDataSetC As DataSet
    Private m_DGVds As DataSet
    Private md_s As DataSet
    Private DSCount As DataSet
    Private bFind As Boolean
    Private Fields As String

    Private WithEvents MainForm As Frm_MainForm


    Public Property SelectObject() As Frm_MainForm
        Get
            Return MainForm
        End Get
        Set(ByVal value As Frm_MainForm)
            MainForm = value
        End Set
    End Property


#Region "interface define"


    Public Function ActionAdd() As Boolean Implements IDServer.IDServer.IDServer.ActionAdd

    End Function

    Public Function ActionCancel() As Boolean Implements IDServer.IDServer.IDServer.ActionCancel

    End Function

    Public Function ActionDelete() As Boolean Implements IDServer.IDServer.IDServer.ActionDelete

    End Function

    Public Function ActionEdit() As Boolean Implements IDServer.IDServer.IDServer.ActionEdit

    End Function

    Public Function ActionExport() As Boolean Implements IDServer.IDServer.IDServer.ActionExport
        Try
            If App.ExportEnable = False Then
                MessageBox.Show(My.resources.NotAllowExport, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Information)
                Exit Function
            End If
            Select Case Me.TabControl1.SelectedIndex
                Case 0
                    SaveXls(mDatasetA.Tables(0))
                Case 1
                Case 2
                    SaveXls(DSCount.Tables(0))
            End Select
        Catch ex As Exception
            MessageBox.Show(ex.ToString, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Information)
        End Try
    End Function

    Public Function ActionFilter() As Boolean Implements IDServer.IDServer.IDServer.ActionFilter

    End Function

    Public Function ActionGoFirst() As Boolean Implements IDServer.IDServer.IDServer.ActionGoFirst

    End Function

    Public Function ActionGoLast() As Boolean Implements IDServer.IDServer.IDServer.ActionGoLast

    End Function

    Public Function ActionGoNext() As Boolean Implements IDServer.IDServer.IDServer.ActionGoNext

    End Function

    Public Function ActionGoPrevious() As Boolean Implements IDServer.IDServer.IDServer.ActionGoPrevious

    End Function

    Public Function ActionImport() As Boolean Implements IDServer.IDServer.IDServer.ActionImport

    End Function

    Public Function ActionInitialize() As Boolean Implements IDServer.IDServer.IDServer.ActionInitialize

    End Function

    Public Function ActionPrint() As Boolean Implements IDServer.IDServer.IDServer.ActionPrint
        Dim Frm As New Frm_Wating
        Try

            If DSCount.Tables(0).Rows.Count <= 0 Then
                MsgBox("對不起，沒有數據可列印！", MsgBoxStyle.Information + MsgBoxStyle.OkOnly, Msg.CompanyName)
                Exit Function
            End If

            If Me.DGV_SaleStat.Rows.Count <= 0 Then
                MsgBox("對不起，沒有數據可列印！", MsgBoxStyle.Information + MsgBoxStyle.OkOnly, Msg.CompanyName)
                Exit Function
            End If
            Frm.Show()
            Dim Pathstr As String = ""
            Dim ConfigNode() As String = ReadConfigFile.Split(";")
            Dim mServer As String = ""
            Dim mDataBase As String = ""
            Dim mUserID As String = ""
            Dim mPassword As String = ""
            Dim sql As String = ""

            If Me.RBSaleOrdeNo.Checked = True Then
                Pathstr = GetReportPath("SAL", "RBSaleOrdeNo.rpt")
            ElseIf Me.RBDept.Checked = True Then
                Pathstr = GetReportPath("SAL", "RBDept.rpt")
            ElseIf Me.RBBarCode.Checked = True Then
                Pathstr = GetReportPath("SAL", "RBBarCode.rpt")
            ElseIf Me.RBCode.Checked = True Then
                Pathstr = GetReportPath("SAL", "RBBarCode.rpt")
            ElseIf Me.RBSaleMan.Checked = True Then
                Pathstr = GetReportPath("SAL", "RBSaleMan.rpt")
            ElseIf Me.RBShop.Checked = True Then
                Pathstr = GetReportPath("SAL", "RBShop.rpt")
            Else
                Pathstr = GetReportPath("SAL", "RBPayType.rpt")
            End If

            For i As Integer = 0 To ConfigNode.Length - 1
                If ConfigNode(i).Split("=")(0).ToLower = "Server".ToLower Then
                    mServer = ConfigNode(i).Split("=")(1)
                End If
                If ConfigNode(i).Split("=")(0).ToLower = "DataBase".ToLower Then
                    mDataBase = ConfigNode(i).Split("=")(1)
                End If
                If ConfigNode(i).Split("=")(0).ToLower = "Uid".ToLower Then
                    mUserID = ConfigNode(i).Split("=")(1)
                End If
                If ConfigNode(i).Split("=")(0).ToLower = "Pwd".ToLower Then
                    mPassword = ConfigNode(i).Split("=")(1)
                End If
            Next

            Dim myReportDoc As New CrystalDecisions.CrystalReports.Engine.ReportDocument
            Dim myParameterValues As New CrystalDecisions.Shared.ParameterValues
            Dim myDiscreteValue As New CrystalDecisions.Shared.ParameterDiscreteValue

            Dim logonInfo As New CrystalDecisions.Shared.TableLogOnInfo
            Dim table As CrystalDecisions.CrystalReports.Engine.Table
            myReportDoc.Load(Pathstr)

            For Each table In myReportDoc.Database.Tables
                logonInfo = table.LogOnInfo
                With logonInfo.ConnectionInfo
                    .ServerName = mServer
                    .DatabaseName = mDataBase
                    .UserID = mUserID
                    .Password = mPassword
                End With
                table.ApplyLogOnInfo(logonInfo)
            Next


            If Me.TabControl1.SelectedIndex = 2 Then
                If DSCount.Tables(0).Rows.Count > 0 Then
                    myReportDoc.SetDataSource(DSCount.Tables(0))
                End If
            Else
                myReportDoc.SetDataSource(CType(DataGridView1.DataSource, DataTable))
                myReportDoc.SetParameterValue("a.BuiltDate ", FormatDate(Me.txtStartDate.Value))
                myReportDoc.SetParameterValue("a.BuiltDate ", FormatDate(Me.txtEndDate.Value))
                ''myReportDoc.SetParameterValue("f.listA ", PubUserCode)

            End If



            My.Forms.Frm_Report.CrystalReportViewer1.ReportSource = myReportDoc
            Dim TxtStartDate As CrystalDecisions.CrystalReports.Engine.TextObject = myReportDoc.ReportDefinition.ReportObjects("StartDate")
            Dim TxtEndDate As CrystalDecisions.CrystalReports.Engine.TextObject = myReportDoc.ReportDefinition.ReportObjects("EndDate")
            TxtStartDate.Text = Format(Me.txtEndDate.Value.ToString("yyyy/MM/dd"), "yyyy/MM/dd")
            TxtEndDate.Text = Format(Me.txtStartDate.Value.ToString("yyyy/MM/dd"), "yyyy/MM/dd")
            My.Forms.Frm_Report.CrystalReportViewer1.Zoom(1)
            My.Forms.Frm_Report.CrystalReportViewer1.DisplayGroupTree = False

            Frm.Dispose()
            Frm_Report.ShowDialog()

        Catch ex As Exception
            MsgBox("對不起，打印出錯！" & ex.Message & ex.ToString, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, Msg.CompanyName)
        End Try
    End Function

    Public Function ActionSave() As Boolean Implements IDServer.IDServer.IDServer.ActionSave

    End Function

    Public Function ActionSelect() As Boolean Implements IDServer.IDServer.IDServer.ActionSelect

    End Function

#End Region


#Region "sub or function "
    Private Sub LoadUser()
        Try
            Dim sql As String = ""
            Dim UserDs As New DataSet
            sql = "select distinct  usercode,username  from sys_usermanage"
            UserDs = ReturnDataset(sql)
            Me.CmbOpterator.ValueMember = "usercode"
            Me.CmbOpterator.DisplayMember = "username"
            Me.CmbOpterator.DataSource = UserDs.Tables(0)
            Me.CmbOpterator.Text = ""
        Catch ex As Exception
            MsgBox("LoadUser:" + ex.ToString, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, Msg.CompanyName)
        End Try
    End Sub
    Private Sub LoadSaleMan()
        Try
            Dim sql As String = ""
            Dim SaleManDs As New DataSet
            sql = "select  distinct  fCode,fCName from dbo.BSC_Employee  where Isnull(fCName,'')<>''"
            SaleManDs = ReturnDataset(sql)
            Me.CmbSaleMan.ValueMember = "fCode"
            Me.CmbSaleMan.DisplayMember = "fCName"
            Me.CmbSaleMan.DataSource = SaleManDs.Tables(0)
            Me.CmbSaleMan.Text = ""
        Catch ex As Exception
            MsgBox("LoadSaleMan:" + ex.ToString, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, Msg.CompanyName)
        End Try
    End Sub

    Private Sub LoadShopName()
        Try
            Dim sql As String = ""
            sql = "select * from BSC_Dept"
            M_Ds = ReturnDataset(sql)
            If M_Ds.Tables(0).Rows.Count > 0 Then
                For Each mRow As DataRow In M_Ds.Tables(0).Rows
                    Me.CmbShopNo.Items.Add(mRow("fCode") & "    " & mRow("fCName"))
                Next
            End If
        Catch ex As Exception
            MsgBox("LoadShopName;" + ex.ToString, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, Msg.CompanyName)
        End Try
    End Sub

    Private Sub BindDataSetA()
        Try
            Dim mTable As New DataTable
            mDatasetA = New DataSet
            With mTable
                .Columns.Add("SaleOrdeNo")
                .Columns.Add("WriteOrdeNo")
                .Columns.Add("CustomerNo")
                .Columns.Add("SaleMan")
                .Columns.Add("SaleDate")
                .Columns.Add("SumCount")
                .Columns.Add("SumMoney")
                .Columns.Add("OperateMan")
                .Columns.Add("OperateDate")
                .Columns.Add("ShopNo")
                .Columns.Add("CounterNo")
                .Columns.Add("PayMoneyType")
                .Columns.Add("PayMoneyCardNo")
                .Columns.Add("PayMoney")
                .Columns.Add("LittleMoney")
                .Columns.Add("OrdeStatus")
            End With
            With Me.DGV_MasterSum
                .ReadOnly = True
                .AllowUserToAddRows = False
                .AllowUserToDeleteRows = False
                .ColumnHeadersVisible = False
                .Columns.Add("SaleOrdeNo", "")
                .Columns.Add("WriteOrdeNo", "")
                .Columns.Add("CustomerNo", "")
                .Columns.Add("SaleMan", "")
                .Columns.Add("SaleDate", "")
                .Columns.Add("SumCount", "")
                .Columns.Add("SumMoney", "")
                .Columns.Add("OperateMan", "")
                .Columns.Add("OperateDate", "")
                .Columns.Add("ShopNo", "")
                .Columns.Add("CounterNo", "")
                .Columns.Add("PayMoneyType", "")
                .Columns.Add("PayMoneyCardNo", "")
                .Columns.Add("PayMoney", "")
                .Columns.Add("LittleMoney", "")
                .Columns.Add("OrdeStatus", "")
            End With
            mDatasetA.Tables.Add(mTable)
            Me.DataGridView1.DataSource = mDatasetA.Tables(0)
            With Me.DataGridView1
                For i As Integer = 0 To .Columns.Count - 1
                    Dim mKey As String = .Columns(i).Name
                    Dim CaptionStr As String = BindHash(0).Item(mKey)
                    .Columns(i).HeaderText = CaptionStr
                Next
            End With
            With Me.DataGridView1
                .AllowUserToAddRows = False
                .AllowUserToDeleteRows = False
                .ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
                .AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.DisplayedCells
                .SelectionMode = DataGridViewSelectionMode.FullRowSelect
                .ReadOnly = True
                .ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
                .Columns("SumCount").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
                .Columns("SumMoney").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
                .Columns("PayMoney").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
                .Columns("LittleMoney").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
            End With
            SetGridCaptionVisible(Me.DataGridView1, Fields, "Frm_SALPOSrecordFind")

            With Me.DGV_MasterSum
                Dim GridRow As New DataGridViewRow
                .Rows.Add(GridRow)
                .Columns("SumCount").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
                .Columns("SumMoney").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
                .Columns("PayMoney").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
                .Columns("LittleMoney").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
                .ScrollBars = ScrollBars.None
                .Rows(0).DefaultCellStyle.BackColor = Color.AliceBlue
                .Rows(0).Cells(0).Value = "合計："
            End With
            SetGridWidth(0)
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Private Sub BindDataSetB()
        Try
            Dim mTable As DataTable
            mDatasetB = New DataSet
            mDataSetC = New DataSet
            mTable = New DataTable
            With mTable
                .Columns.Add("SaleOrdeNo")
                .Columns.Add("GoodsBarCode")
                .Columns.Add("GoodsCode")
                .Columns.Add("GoodsName")
                .Columns.Add("GoodsCount")
                .Columns.Add("GoodsPrice")
                .Columns.Add("ColorCName")
                .Columns.Add("SizeSName")
            End With
            mDatasetB.Tables.Add(mTable)
            Me.DGV_Old.DataSource = mDatasetB.Tables(0)
            With Me.DGV_Old
                For i As Integer = 0 To .Columns.Count - 1
                    Dim mKey As String = .Columns(i).Name
                    Dim CaptionStr As String = BindHash(1).Item(mKey)
                    .Columns(i).HeaderText = CaptionStr
                    .Columns(i).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
                Next
            End With
            With Me.DGV_Old
                .AllowUserToAddRows = False
                .AllowUserToDeleteRows = False
                .AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.DisplayedCells
                .SelectionMode = DataGridViewSelectionMode.FullRowSelect
                .ReadOnly = True
            End With


            mTable = New DataTable
            With mTable
                .Columns.Add("SaleOrdeNo")
                .Columns.Add("GoodsBarCode")
                .Columns.Add("GoodsCode")
                .Columns.Add("GoodsName")
                .Columns.Add("GoodsCount")
                .Columns.Add("GoodsMoney")
                .Columns.Add("EditPerson")
                .Columns.Add("EditDate")
                .Columns.Add("ShopNo")
            End With
            mDataSetC.Tables.Add(mTable)
            Me.DGV_New.DataSource = mDataSetC.Tables(0)
            With Me.DGV_New
                For i As Integer = 0 To .Columns.Count - 1
                    Dim mKey As String = .Columns(i).Name
                    Dim CaptionStr As String = BindHash(2).Item(mKey)
                    .Columns(i).HeaderText = CaptionStr
                    .Columns(i).HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter
                Next
            End With

            With Me.DGV_New
                .AllowUserToAddRows = False
                .AllowUserToDeleteRows = False
                .AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.DisplayedCells
                .SelectionMode = DataGridViewSelectionMode.FullRowSelect
                .ReadOnly = True
            End With
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Private Sub BindDGV_SaleState()
        Try
            Dim mTable As New DataTable
            m_DGVds = New DataSet
            With mTable
                .Columns.Add("Dept")
                .Columns.Add("SaleOrdeCount")
                .Columns.Add("GoodsBarCode")
                .Columns.Add("GoodsCode")
                .Columns.Add("GoodsShortName")
                .Columns.Add("GoodsCnName")
                .Columns.Add("ColorCName")
                .Columns.Add("SizeSName")
                .Columns.Add("SaleOrdeNo")
                .Columns.Add("SumCount")
                .Columns.Add("SumMoney")
                .Columns.Add("SaleMan")
                .Columns.Add("fCName")
                .Columns.Add("ShopNo")
                .Columns.Add("ShopName")
                .Columns.Add("PayMoneyType")
                .Columns.Add("PayMoneyName")
            End With

            With Me.DGV_Sum
                .ReadOnly = True
                .AllowUserToAddRows = False
                .AllowUserToDeleteRows = False
                .ColumnHeadersVisible = False
                .Columns.Add("Dept", "")
                .Columns.Add("SaleOrdeCount", "")
                .Columns.Add("SumCount", "")
                .Columns.Add("SumMoney", "")
                .Columns.Add("GoodsBarCode", "")
                .Columns.Add("GoodsCode", "")
                .Columns.Add("GoodsShortName", "")
                .Columns.Add("GoodsCnName", "")
                .Columns.Add("ColorCName", "")
                .Columns.Add("SaleOrdeNo", "")
                .Columns.Add("SizeSName", "")
                .Columns.Add("SaleMan", "")
                .Columns.Add("fCName", "")
                .Columns.Add("ShopNo", "")
                .Columns.Add("ShopName", "")
                .Columns.Add("PayMoneyType", "")
                .Columns.Add("PayMoneyName", "")
            End With
            m_DGVds.Tables.Add(mTable)
            Me.DGV_SaleStat.DataSource = m_DGVds.Tables(0)
            With Me.DGV_SaleStat
                For i As Integer = 0 To .Columns.Count - 1
                    Dim mKey As String = .Columns(i).Name
                    Dim CaptionStr As String = BindHash(3).Item(mKey)
                    .Columns(i).HeaderText = CaptionStr
                Next
                With Me.DGV_SaleStat
                    .ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
                    .Columns("SaleOrdeCount").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
                    .Columns("SumCount").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
                    .Columns("SumMoney").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
                    .RowsDefaultCellStyle.BackColor = Color.AliceBlue
                End With
            End With

            With Me.DGV_Sum
                Dim GridRow As New DataGridViewRow
                .Rows.Add(GridRow)
                .Columns("SaleOrdeCount").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
                .Columns("SumCount").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
                .Columns("SumMoney").DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight
                .ScrollBars = ScrollBars.None
                .Rows(0).DefaultCellStyle.BackColor = Color.AliceBlue
            End With
            SetGridWidth(1)
        Catch ex As Exception
            MsgBox("BindDGV_SaleState:" + ex.ToString, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, Msg.CompanyName)
        End Try
    End Sub

    Private Function BindHash(Optional ByVal Index As Integer = 0) As Hashtable
        Try
            Dim mHash As New Hashtable
            With mHash
                Select Case Index
                    Case 0
                        .Add("SaleOrdeNo", "銷售單號")
                        .Add("WriteOrdeNo", "手寫單號")
                        .Add("CustomerNo", "客戶名稱")
                        .Add("SaleMan", "業務員")
                        .Add("SaleDate", "銷售日期")
                        .Add("SumCount", "銷售數量")
                        .Add("SumMoney", "總金額")
                        .Add("OperateMan", "操作者")
                        .Add("OperateDate", "操作日期")
                        .Add("ShopNo", "門店編號")
                        .Add("CounterNo", "柜臺編號")
                        .Add("PayMoneyType", "付款類型")
                        .Add("PayMoneyCardNo", "客戶卡號")
                        .Add("PayMoney", "付款金額")
                        .Add("LittleMoney", "找零金額")
                        .Add("OrdeStatus", "單據狀態")
                    Case 1
                        .Add("SaleOrdeNo", "銷售單號")
                        .Add("GoodsBarCode", "貨品條碼")
                        .Add("GoodsCode", "貨品編號")
                        .Add("GoodsName", "貨品名稱")
                        .Add("GoodsCount", "數量")
                        .Add("GoodsPrice", "金額")
                        .Add("ColorCName", "顏色")
                        .Add("SizeSName", "規格")
                    Case 2
                        .Add("SaleOrdeNo", "銷售單號")
                        .Add("GoodsBarCode", "貨品條碼")
                        .Add("GoodsCode", "貨品編號")
                        .Add("GoodsName", "貨品名稱")
                        .Add("GoodsCount", "購買數量")
                        .Add("GoodsMoney", "金額")
                        .Add("EditPerson", "修改人")
                        .Add("EditDate", "修改日期")
                        .Add("ShopNo", "所屬店鋪")
                    Case 3
                        .Add("SaleMan", "銷售員編號")
                        .Add("fCName", "銷售員名稱")
                        .Add("SaleOrdeNo", "銷售單號")
                        .Add("SaleOrdeCount", "銷售單數")
                        .Add("SumCount", "銷售數量")
                        .Add("SumMoney", "銷售金額")
                        .Add("GoodsBarCode", "貨品條碼")
                        .Add("GoodsCode", "貨品編號")
                        .Add("GoodsShortName", "貨品簡稱")
                        .Add("GoodsCnName", "中文名稱")
                        .Add("ColorCName", "顏色")
                        .Add("SizeSName", "規格")
                        .Add("Dept", "部門")
                        .Add("ShopNo", "店鋪編號")
                        .Add("ShopName", "店鋪名稱")
                        .Add("PayMoneyType", "付款類型")
                End Select

            End With
            Return mHash
        Catch ex As Exception
            Throw ex
        End Try
    End Function

    Private Sub FillGridView2(ByVal SaleOrdeNo As String)
        Try
            Dim sql As String = ""
            sql = "select a.SaleOrdeNo,replace(a.GoodsBarCode,'*','') as GoodsBarCode,b.Code as GoodsCode,b.CnName as GoodsName,c.ColorCName,a.GoodsCount,a.GoodsPrice,d.SizeSName from Sal_PosB a inner join BSC_Goods b on a.GoodsBarCode=b.BarCode inner join BSC_ColorDefine c on b.Color=c.ColorCode inner join BSC_SizeDefine d on b.Spec=d.SizeCode where SaleOrdeNo='" & SaleOrdeNo & "'"
            mDatasetB = New DataSet
            mDatasetB = ReturnDataset(sql)
            Me.DGV_Old.DataSource = mDatasetB.Tables(0)
            sql = "select a.SaleOrdeNo,replace(a.GoodsBarCode,'*','') as GoodsBarCode,b.Code as GoodsCode,b.CnName as GoodsName,a.GoodsCount,a.GoodsMoney,a.EditPerson,Convert(varchar(10),c.EditDate,21) as EditDate,a.ShopNo "
            sql += "from SAL_GoodsBACK a inner join BSC_Goods b on a.GoodsBarCode=b.BarCode left join "
            sql += " (select SaleOrdeNo,max(BuiltDate) as EditDate from SAL_GoodsBACK group by SaleOrdeNo) c on a.SaleOrdeNo=c.SaleOrdeNo where a.builtDate=c.EditDate and a.SaleOrdeNo='" & SaleOrdeNo & "'"

            mDataSetC = New DataSet
            mDataSetC = ReturnDataset(sql)
            Me.DGV_New.DataSource = mDataSetC.Tables(0)
        Catch ex As Exception
            MsgBox("FillGridView2:" + ex.ToString, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, Msg.CompanyName)
        End Try
    End Sub

    Private Sub SetGridWidth(ByVal index As Integer)
        Select Case index
            Case 0
                For i As Integer = 0 To Me.DataGridView1.Columns.Count - 1
                    Me.DGV_MasterSum.Columns(i).Width = Me.DataGridView1.Columns(i).Width
                Next
            Case 1
                For i As Integer = 0 To Me.DGV_SaleStat.Columns.Count - 1
                    Me.DGV_Sum.Columns(i).Width = Me.DGV_SaleStat.Columns(i).Width
                Next
        End Select

    End Sub

    Private Sub GetToolEnable()
        Try
            With MainForm
                .ToolStripAdd.Enabled = False
                .ToolStripEdit.Enabled = False
                .ToolStripDelete.Enabled = False
                .ToolStripPrint.Enabled = PrintEnable
                .ToolStripImport.Enabled = ImportEnable
                .ToolStripExport.Enabled = ExportEnable
                .ToolStripFind.Enabled = FindEnable
                .ToolStripCheck.Enabled = False
                .ToolStripUnCheck.Enabled = False
                .ToolStripComplete.Enabled = False
                .AddToolStripMenuItem.Enabled = .ToolStripAdd.Enabled
                .Edit1ToolStripMenuItem.Enabled = .ToolStripEdit.Enabled
                .DelToolStripMenuItem.Enabled = .ToolStripDelete.Enabled
                .SaveToolStripMenuItem.Enabled = .ToolStripSave.Enabled
                .CancelToolStripMenuItem.Enabled = .ToolStripCancel.Enabled
                .PrintToolStripMenuItem.Enabled = .ToolStripPrint.Enabled
                .ExportToolStripMenuItem.Enabled = .ToolStripImport.Enabled
                .ImportToolStripMenuItem.Enabled = .ToolStripExport.Enabled
                .FilterToolStripMenuItem.Enabled = .ToolStripFilter.Enabled
            End With

        Catch ex As Exception
            MsgBox("GetToolEnable:" + ex.ToString, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, Msg.CompanyName)
        End Try
    End Sub
#End Region


#Region "Windows Evenst"

    Private Sub Frm_SALPOSrecordFind_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            BindDataSetA()
            BindDataSetB()
            BindDGV_SaleState()
            LoadShopName()
            LoadSaleMan()
            LoadUser()
            Me.CheckBox1.Checked = True
            Me.CheckBox2.Checked = True
        Catch ex As Exception
            MsgBox(My.resources.LoadFormError, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, Msg.CompanyName)
        End Try
    End Sub

    Private Sub TabControl1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TabControl1.SelectedIndexChanged
        Try
            If Not Me.TabControl1.SelectedTab Is Nothing Then
                Select Case Me.TabControl1.SelectedIndex
                    Case 0
                    Case 1
                        If mDatasetA.Tables(0).Rows.Count <= 0 Then
                        Else
                            FillGridView2(Me.DataGridView1.CurrentRow.Cells("SaleOrdeNo").Value)
                        End If
                End Select
            End If

        Catch ex As Exception
            MsgBox("TabControl1_SelectedIndexChanged:" + ex.ToString, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, Msg.CompanyName)
        End Try
    End Sub

    Private Sub BtnFind_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnFind.Click
        Try
            Dim sql As String = ""
            Dim WhereStr As String = ""
            If Me.txtOrdeNo.Text.Length > 0 Then
                WhereStr = " and SaleOrdeNo='" & Me.txtOrdeNo.Text.Replace("'", "") & "'"
            End If
            If Me.txtWriteNo.Text.Length > 0 Then
                WhereStr += " and WriteOrdeNo='" & Me.txtWriteNo.Text.Replace("'", "") & "'"
            End If
            If Me.CmbShopNo.Text.Length > 0 Then
                WhereStr += " and ShopNo='" & Me.CmbShopNo.SelectedItem.ToString.Split("    ")(0) & "'"
            End If
            If Me.CmbSaleMan.Text.Length > 0 Then
                WhereStr += " and Saleman='" & Me.CmbSaleMan.SelectedValue & "'"
            End If
            If Me.CmbOpterator.Text.Length > 0 Then
                WhereStr += " and Operateman='" & Me.CmbOpterator.SelectedValue & "'"
            End If
            If Me.DtpFrom.Checked = True And Me.DtpTo.Checked = True Then
                WhereStr += " and OperateDate between '" & Me.DtpFrom.Text & "'  and '" & Me.DtpTo.Text & "'"
            End If
            If PubCompanyCode <> "" Then
            Else
            End If
            sql = "select distinct a.SaleOrdeNo,a.WriteOrdeNo,replace(a.CustomerNo,'*','') as CustomerNo,a.SaleMan,a.SaleDate,a.SumMoney,a.SumCount,a.OperateMan,a.OperateDate,a.ShopNo,a.CounterNo,a.LittleMoney,OrdeStatus=case a.OrdeStatus when 0 then '未修改' else '已修改' end from Sal_PosA a where ShopNo='" & PubCompanyCode & "'" & WhereStr
            mDatasetA = New DataSet
            mDatasetA = ReturnDataset(sql)
            Me.DataGridView1.DataSource = mDatasetA.Tables(0)
            If mDatasetA.Tables(0).Rows.Count > 0 Then
                Me.DGV_MasterSum.Rows(0).Cells("SumCount").Value = Format(mDatasetA.Tables(0).Compute("sum(SumCount)", ""), "#0.00")
                Me.DGV_MasterSum.Rows(0).Cells("SumMoney").Value = Format(mDatasetA.Tables(0).Compute("sum(SumMoney)", ""), "#0.00")
                Me.DGV_MasterSum.Rows(0).Cells("LittleMoney").Value = Format(mDatasetA.Tables(0).Compute("sum(LittleMoney)", ""), "#0.00")
                bFind = mDatasetA.Tables(0).Rows.Count > 0
                For i As Integer = 0 To Me.DataGridView1.RowCount - 2
                    If Me.DataGridView1.Rows(i).Cells("OrdeStatus").Value Is System.DBNull.Value Then Exit Sub
                    If Me.DataGridView1.Rows(i).Cells("OrdeStatus").Value = "已修改" Then
                        Me.DataGridView1.Rows(i).DefaultCellStyle.BackColor = Color.Yellow
                    Else
                        Me.DataGridView1.Rows(i).DefaultCellStyle.BackColor = Color.AliceBlue
                    End If
                Next
            Else
                MessageBox.Show("The record is 0", "加朗軟件", MessageBoxButtons.OK, MessageBoxIcon.Information)
            End If
            GetToolEnable()
            MainForm.ToolStripPrint.Enabled = False

        Catch ex As Exception
            MsgBox(My.Resources.ErrFind, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, Msg.CompanyName)
        End Try
    End Sub

    Private Sub DataGridView1_ColumnWidthChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewColumnEventArgs) Handles DataGridView1.ColumnWidthChanged
        SetGridWidth(0)
    End Sub

    Private Sub DataGridView1_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView1.DoubleClick
        Try
            If Me.TabControl1.SelectedIndex = 0 Then
                Me.TabControl1.SelectedIndex = 1
            End If
        Catch ex As Exception
            MsgBox("DataGridView1_DoubleClick:" + ex.ToString, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, Msg.CompanyName)
        End Try
    End Sub

    Private Sub DataGridView1_Scroll(ByVal sender As Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles DataGridView1.Scroll
        Me.DGV_MasterSum.FirstDisplayedScrollingColumnIndex = Me.DataGridView1.FirstDisplayedScrollingColumnIndex
        Me.DGV_MasterSum.HorizontalScrollingOffset = Me.DataGridView1.HorizontalScrollingOffset
    End Sub

#End Region



#Region "TabControlPage3"


    Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnFind1.Click
        Try
            Dim sql As String = ""
            Dim WhereCondition As String = ""
            Dim StartDate As String = Me.txtStartDate.Text
            Dim EndDate As String = Me.txtEndDate.Text
            DSCount = New DataSet

            If Me.CheckBox1.Checked = True And Me.CheckBox2.Checked = False Then
                WhereCondition += " and Convert(varchar(10),a.BuiltDate,21) = '" & StartDate & "'"
            ElseIf Me.CheckBox1.Checked = False And Me.CheckBox2.Checked = True Then
                WhereCondition += " and Convert(varchar(10),a.BuiltDate,21) ='" & EndDate & "'"
            ElseIf Me.CheckBox1.Checked = True And Me.CheckBox2.Checked = True Then
                WhereCondition += " and Convert(varchar(10),a.BuiltDate,21) between '" & StartDate & "' and '" & EndDate & "'"
            End If

            If Me.RBDept.Checked = True Then
                sql = "select (d.fcname) as Dept,Count(Distinct a.SaleOrdeNo) as SaleOrdeCount,sum(b.goodscount) as SumCount,sum(b.goodsprice) as SumMoney from  Sal_PosA a left join Sal_PosB b on  "
                sql += "a.SaleOrdeNo = b.SaleOrdeNo left join BSC_Goods c on  b.GoodsBarCode=c.BarCode left join BSC_GoodsType d on  c.Dept = d.fcode where 1=1 " & WhereCondition & " group by d.fcname"
            End If

            If Me.RBSaleOrdeNo.Checked = True Then
                sql = "select a.SaleOrdeNo,replace(b.GoodsBarCode,'*','') as GoodsBarCode,sum(b.goodscount) as SumCount, "
                sql += " sum(b.goodsprice) as SumMoney,d.fCName,c.fCName as ShopName  from  Sal_PosA a  left join Sal_PosB b on  "
                sql += "a.SaleOrdeNo= b.SaleOrdeNo left join BSC_Dept c on a.shopNo = c.fCode  left  join BSC_Employee d on  a.SaleMan=d.fCode "
                sql += " where 1=1 " & WhereCondition & " group by a.SaleOrdeNo,b.GoodsBarCode,d.fCName,c.fCName"

            End If

            If Me.RBBarCode.Checked = True Then
                sql = " select  replace(b.GoodsBarCode,'*','') as GoodsBarCode,c.Code as GoodsCode,c.ShortName as GoodsShortName,c.CnName as GoodsCnName,d.ColorCName,e.SizeSName,sum(b.goodscount) as SumCount,sum(b.goodsprice) as SumMoney "
                sql += " from Sal_PosA a left join Sal_PosB B on a.SaleOrdeNo = b.SaleOrdeNo "
                sql += " left join BSC_Goods c on b.GoodsBarCode=c.BarCode left join BSC_ColorDefine d on c.Color=d.ColorCode"
                sql += " left join BSC_SizeDefine e on c.Spec=e.SizeCode  where 1=1 " & WhereCondition & " GROUP BY b.GoodsBarCode,c.Code,c.ShortName,c.CnName,d.ColorCName,e.SizeSName"
            End If

            If Me.RBCode.Checked = True Then
                sql = " select  replace(b.GoodsBarCode,'*','') as GoodsBarCode,c.Code as GoodsCode,c.ShortName as GoodsShortName,c.CnName as GoodsCnName,d.ColorCName,e.SizeSName,sum(b.goodscount) as SumCount,sum(b.goodsprice) as SumMoney "
                sql += " from Sal_PosA a left join Sal_PosB B on a.SaleOrdeNo = b.SaleOrdeNo "
                sql += " left join BSC_Goods c on b.GoodsBarCode=c.BarCode left join BSC_ColorDefine d on c.Color=d.ColorCode"
                sql += " left join BSC_SizeDefine e on c.Spec=e.SizeCode  where 1=1 " & WhereCondition & " GROUP BY b.GoodsBarCode,c.Code,c.ShortName,c.CnName,d.ColorCName,e.SizeSName"
            End If

            If Me.RBSaleMan.Checked = True Then
                sql = "select b.fCName,Count(Distinct a.SaleOrdeNo) as SaleOrdeCount,sum(c.goodscount) as SumCount,sum(c.goodsprice) as SumMoney ,SaleMan"
                sql += " from Sal_PosA a left  join BSC_Employee b on a.SaleMan=b.fCode  left join Sal_PosB c on a.SaleOrdeNo= c.SaleOrdeNo where 1=1 " & WhereCondition & " Group by SaleMan,b.fCName "
            End If

            If Me.RBShop.Checked = True Then
                sql = "select a.ShopNo,Count(Distinct a.SaleOrdeNo) as SaleOrdeCount,sum(c.goodscount) as SumCount,sum(c.goodsprice) as SumMoney ,b.fCName as ShopName "
                sql += "from Sal_PosA a left join BSC_Dept b on a.shopNo = b.fCode left join Sal_PosB c on a.SaleOrdeNo= c.SaleOrdeNo where 1=1 " & WhereCondition & " Group by a.ShopNo ,b.fCname "
            End If

            If Me.RBPayType.Checked = True Then
                sql = "select  PayMoneyType,Sum(PayMoney)as SumMoney  from   Sal_PosC b left join Sal_PosA  a on a.SaleOrdeNo = b.SaleOrdeNO   "
                sql += " where 1=1 " & WhereCondition & " GROUP BY payMoneyType "
            End If


            DSCount = ReturnDataset(sql)
            SetGridColumnVisible(DSCount)
            GetToolEnable()
            Me.DGV_SaleStat.ReadOnly = True
        Catch ex As Exception
            MsgBox("Button1_Click" + ex.ToString, MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, Msg.CompanyName)
        End Try
    End Sub

    Private Sub SetGridColumnVisible(ByVal mds As DataSet)
        Try
            BindDGV_SaleState()
            If mds.Tables(0).Rows.Count <= 0 Then Exit Sub
            Me.DGV_Sum.Rows(0).Cells("SaleOrdeCount").Value = ""
            Me.DGV_Sum.Rows(0).Cells("SumCount").Value = ""
            Me.DGV_Sum.Rows(0).Cells("SumMoney").Value = ""
            If Me.RBDept.Checked = True Then
                Me.DGV_SaleStat.DataSource = mds.Tables(0)
                Me.DGV_Sum.Rows(0).Cells("SaleOrdeCount").Value = Format(mds.Tables(0).Compute("sum(SaleOrdeCount)", ""), "#0.00")
                Me.DGV_Sum.Rows(0).Cells("SumCount").Value = Format(mds.Tables(0).Compute("sum(SumCount)", ""), "#0.00")
                Me.DGV_Sum.Rows(0).Cells("SumMoney").Value = Format(mds.Tables(0).Compute("sum(SumMoney)", ""), "#0.00")
                For i As Integer = 0 To Me.DGV_SaleStat.Columns.Count - 1
                    If Me.DGV_SaleStat.Columns(i).Name = "Dept" Or Me.DGV_SaleStat.Columns(i).Name = "SaleOrdeCount" Or Me.DGV_SaleStat.Columns(i).Name = "SumCount" Or Me.DGV_SaleStat.Columns(i).Name = "SumMoney" Then
                        Me.DGV_SaleStat.Columns(i).Visible = True
                    Else
                        Me.DGV_SaleStat.Columns(i).Visible = False
                    End If
                Next
            End If

            If Me.RBBarCode.Checked = True Then
                Me.DGV_SaleStat.DataSource = mds.Tables(0)
                Me.DGV_Sum.Rows(0).Cells("SumCount").Value = Format(mds.Tables(0).Compute("sum(SumCount)", ""), "#0.00")
                Me.DGV_Sum.Rows(0).Cells("SumMoney").Value = Format(mds.Tables(0).Compute("sum(SumMoney)", ""), "#0.00")
                For i As Int16 = 0 To Me.DGV_SaleStat.Columns.Count - 1
                    If Me.DGV_SaleStat.Columns(i).Name = "GoodsCode" Or Me.DGV_SaleStat.Columns(i).Name = "SaleMan" Or Me.DGV_SaleStat.Columns(i).Name = "fCName" Or Me.DGV_SaleStat.Columns(i).Name = "Dept" Or Me.DGV_SaleStat.Columns(i).Name = "SaleOrdeCount" Or Me.DGV_SaleStat.Columns(i).Name = "ShopNo" Or Me.DGV_SaleStat.Columns(i).Name = "ShopName" _
                     Or Me.DGV_SaleStat.Columns(i).Name = "PayMoneyType" Or Me.DGV_SaleStat.Columns(i).Name = "PayMoneyName" Then
                        Me.DGV_SaleStat.Columns(i).Visible = False
                    Else
                        Me.DGV_SaleStat.Columns(i).Visible = True
                    End If
                Next
            End If

            If Me.RBCode.Checked = True Then
                Me.DGV_SaleStat.DataSource = mds.Tables(0)
                Me.DGV_Sum.Rows(0).Cells("SumCount").Value = Format(mds.Tables(0).Compute("sum(SumCount)", ""), "#0.00")
                Me.DGV_Sum.Rows(0).Cells("SumMoney").Value = Format(mds.Tables(0).Compute("sum(SumMoney)", ""), "#0.00")
                For i As Int16 = 0 To Me.DGV_SaleStat.Columns.Count - 1
                    If Me.DGV_SaleStat.Columns(i).Name = "GoodsBarCode" Or Me.DGV_SaleStat.Columns(i).Name = "SaleMan" Or Me.DGV_SaleStat.Columns(i).Name = "fCName" Or Me.DGV_SaleStat.Columns(i).Name = "Dept" Or Me.DGV_SaleStat.Columns(i).Name = "SaleOrdeCount" Or Me.DGV_SaleStat.Columns(i).Name = "ShopNo" Or Me.DGV_SaleStat.Columns(i).Name = "ShopName" _
                     Or Me.DGV_SaleStat.Columns(i).Name = "PayMoneyType" Or Me.DGV_SaleStat.Columns(i).Name = "PayMoneyName" Then
                        Me.DGV_SaleStat.Columns(i).Visible = False
                    Else
                        Me.DGV_SaleStat.Columns(i).Visible = True
                    End If
                Next
            End If

            If Me.RBSaleMan.Checked = True Then
                Me.DGV_SaleStat.DataSource = mds.Tables(0)
                Me.DGV_Sum.Rows(0).Cells("SaleOrdeCount").Value = Format(mds.Tables(0).Compute("sum(SaleOrdeCount)", ""), "#0.00")
                Me.DGV_Sum.Rows(0).Cells("SumCount").Value = Format(mds.Tables(0).Compute("sum(SumCount)", ""), "#0.00")
                Me.DGV_Sum.Rows(0).Cells("SumMoney").Value = Format(mds.Tables(0).Compute("sum(SumMoney)", ""), "#0.00")
                For i As Int16 = 0 To Me.DGV_SaleStat.Columns.Count - 1
                    If Me.DGV_SaleStat.Columns(i).Name = "SaleMan" Or Me.DGV_SaleStat.Columns(i).Name = "fCName" Or Me.DGV_SaleStat.Columns(i).Name = "SaleOrdeCount" Or Me.DGV_SaleStat.Columns(i).Name = "SumCount" Or Me.DGV_SaleStat.Columns(i).Name = "SumMoney" Then
                        Me.DGV_SaleStat.Columns(i).Visible = True
                    Else
                        Me.DGV_SaleStat.Columns(i).Visible = False
                    End If
                Next
            End If

            If Me.RBShop.Checked = True Then
                Me.DGV_SaleStat.DataSource = mds.Tables(0)
                Me.DGV_Sum.Rows(0).Cells("SaleOrdeCount").Value = Format(mds.Tables(0).Compute("sum(SaleOrdeCount)", ""), "#0.00")
                Me.DGV_Sum.Rows(0).Cells("SumCount").Value = Format(mds.Tables(0).Compute("sum(SumCount)", ""), "#0.00")
                Me.DGV_Sum.Rows(0).Cells("SumMoney").Value = Format(mds.Tables(0).Compute("sum(SumMoney)", ""), "#0.00")
                For i As Integer = 0 To Me.DGV_SaleStat.Columns.Count - 1
                    If Me.DGV_SaleStat.Columns(i).Name = "ShopNo" Or Me.DGV_SaleStat.Columns(i).Name = "ShopName" Or Me.DGV_SaleStat.Columns(i).Name = "SaleOrdeCount" Or Me.DGV_SaleStat.Columns(i).Name = "SumCount" Or Me.DGV_SaleStat.Columns(i).Name = "SumMoney" Then
                        Me.DGV_SaleStat.Columns(i).Visible = True
                    Else
                        Me.DGV_SaleStat.Columns(i).Visible = False
                    End If
                Next
            End If

            If Me.RBPayType.Checked = True Then
                Me.DGV_SaleStat.DataSource = mds.Tables(0)
                Me.DGV_Sum.Rows(0).Cells("SumMoney").Value = Format(mds.Tables(0).Compute("sum(SumMoney)", ""), "#0.00")
                For i As Integer = 0 To Me.DGV_SaleStat.Columns.Count - 1
                    If Me.DGV_SaleStat.Columns(i).Name = "PayMoneyType" Or Me.DGV_SaleStat.Columns(i).Name = "PayMoneyName" Or Me.DGV_SaleStat.Columns(i).Name = "SaleOrdeCount" Or Me.DGV_SaleStat.Columns(i).Name = "SumCount" Or Me.DGV_SaleStat.Columns(i).Name = "SumMoney" Then
                        Me.DGV_SaleStat.Columns(i).Visible = True
                    Else
                        Me.DGV_SaleStat.Columns(i).Visible = False
                    End If
                Next
            End If
            If Me.RBSaleOrdeNo.Checked = True Then
                Me.DGV_SaleStat.DataSource = mds.Tables(0)
                Me.DGV_Sum.Rows(0).Cells("SumCount").Value = Format(mds.Tables(0).Compute("sum(SumCount)", ""), "#0.00")
                Me.DGV_Sum.Rows(0).Cells("SumMoney").Value = Format(mds.Tables(0).Compute("sum(SumMoney)", ""), "#0.00")
                For i As Int16 = 0 To Me.DGV_SaleStat.Columns.Count - 1
                    If Me.DGV_SaleStat.Columns(i).Name = "GoodsCode" Or Me.DGV_SaleStat.Columns(i).Name = "SaleMan" Or Me.DGV_SaleStat.Columns(i).Name = "fCName" Or Me.DGV_SaleStat.Columns(i).Name = "Dept" Or Me.DGV_SaleStat.Columns(i).Name = "SaleOrdeCount" Or Me.DGV_SaleStat.Columns(i).Name = "ShopNo" Or Me.DGV_SaleStat.Columns(i).Name = "ShopName" _
                     Or Me.DGV_SaleStat.Columns(i).Name = "PayMoneyType" Or Me.DGV_SaleStat.Columns(i).Name = "PayMoneyName" Then
                        Me.DGV_SaleStat.Columns(i).Visible = False
                    Else
                        Me.DGV_SaleStat.Columns(i).Visible = True
                    End If
                Next
            End If

            ''If Me.RBCustomer.Checked = True Then
            ''    Me.DGV_SaleStat.DataSource = mds.Tables(0)
            ''    Me.DGV_Sum.Rows(0).Cells("SaleOrdeCount").Value = Format(mds.Tables(0).Compute("sum(SaleOrdeCount)", ""), "#0.00")
            ''    Me.DGV_Sum.Rows(0).Cells("SumCount").Value = Format(mds.Tables(0).Compute("sum(SumCount)", ""), "#0.00")
            ''    Me.DGV_Sum.Rows(0).Cells("SumMoney").Value = Format(mds.Tables(0).Compute("sum(SumMoney)", ""), "#0.00")
            ''    For i As Integer = 0 To Me.DGV_SaleStat.Columns.Count - 1
            ''        If Me.DGV_SaleStat.Columns(i).Name = "CustomerNO" Or Me.DGV_SaleStat.Columns(i).Name = "PayMoneyName" Or Me.DGV_SaleStat.Columns(i).Name = "PayMoney" Or Me.DGV_SaleStat.Columns(i).Name = "SumCount" Or Me.DGV_SaleStat.Columns(i).Name = "SumMoney" Then
            ''            Me.DGV_SaleStat.Columns(i).Visible = True
            ''        Else
            ''            Me.DGV_SaleStat.Columns(i).Visible = False
            ''        End If
            ''    Next
            ''End If

            With Me.DGV_SaleStat
                .AllowUserToAddRows = False
                .AllowUserToDeleteRows = False
            End With
            For i As Integer = 0 To Me.DGV_SaleStat.Columns.Count - 1
                Me.DGV_Sum.Columns(i).Visible = Me.DGV_SaleStat.Columns(i).Visible
            Next
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Private Sub DGV_SaleStat_ColumnWidthChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewColumnEventArgs) Handles DGV_SaleStat.ColumnWidthChanged
        SetGridWidth(1)
    End Sub

    Private Sub DGV_SaleStat_Scroll(ByVal sender As Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles DGV_SaleStat.Scroll
        Me.DGV_Sum.FirstDisplayedScrollingColumnIndex = Me.DGV_SaleStat.FirstDisplayedScrollingColumnIndex
        Me.DGV_Sum.HorizontalScrollingOffset = Me.DGV_SaleStat.HorizontalScrollingOffset
    End Sub
#End Region

    Private Sub DateTimePicker2_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DtpTo.ValueChanged

    End Sub

    Private Sub DataGridView1_RowPostPaint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewRowPostPaintEventArgs) Handles DataGridView1.RowPostPaint
        Try
            Dim DGView As DataGridView = DirectCast(sender, DataGridView)
            Dim SBrush As New SolidBrush(DGView.RowHeadersDefaultCellStyle.ForeColor)
            e.Graphics.DrawString(Convert.ToString(e.RowIndex + 1, System.Globalization.CultureInfo.CurrentCulture), e.InheritedRowStyle.Font, SBrush, e.RowBounds.Location.X + 20, e.RowBounds.Location.Y + 4)
        Catch ex As Exception
            MessageBox.Show("DataGridViewstorage_RowPostPaint:" & ex.Message & ex.StackTrace, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try

    End Sub

    Private Sub DGV_Old_RowPostPaint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewRowPostPaintEventArgs) Handles DGV_Old.RowPostPaint

        Try
            Dim DGView As DataGridView = DirectCast(sender, DataGridView)
            Dim SBrush As New SolidBrush(DGView.RowHeadersDefaultCellStyle.ForeColor)
            e.Graphics.DrawString(Convert.ToString(e.RowIndex + 1, System.Globalization.CultureInfo.CurrentCulture), e.InheritedRowStyle.Font, SBrush, e.RowBounds.Location.X + 20, e.RowBounds.Location.Y + 4)
        Catch ex As Exception
            MessageBox.Show("DataGridViewstorage_RowPostPaint:" & ex.Message & ex.StackTrace, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub

    Private Sub DGV_New_RowPostPaint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewRowPostPaintEventArgs) Handles DGV_New.RowPostPaint

        Try
            Dim DGView As DataGridView = DirectCast(sender, DataGridView)
            Dim SBrush As New SolidBrush(DGView.RowHeadersDefaultCellStyle.ForeColor)
            e.Graphics.DrawString(Convert.ToString(e.RowIndex + 1, System.Globalization.CultureInfo.CurrentCulture), e.InheritedRowStyle.Font, SBrush, e.RowBounds.Location.X + 20, e.RowBounds.Location.Y + 4)
        Catch ex As Exception
            MessageBox.Show("DataGridViewstorage_RowPostPaint:" & ex.Message & ex.StackTrace, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub

    Private Sub DGV_SaleStat_RowPostPaint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewRowPostPaintEventArgs) Handles DGV_SaleStat.RowPostPaint

        Try
            Dim DGView As DataGridView = DirectCast(sender, DataGridView)
            Dim SBrush As New SolidBrush(DGView.RowHeadersDefaultCellStyle.ForeColor)
            e.Graphics.DrawString(Convert.ToString(e.RowIndex + 1, System.Globalization.CultureInfo.CurrentCulture), e.InheritedRowStyle.Font, SBrush, e.RowBounds.Location.X + 20, e.RowBounds.Location.Y + 4)
        Catch ex As Exception
            MessageBox.Show("DataGridViewstorage_RowPostPaint:" & ex.Message & ex.StackTrace, Msg.CompanyName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub

    Private Sub Label2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label2.Click

    End Sub
End Class
